<template>
  <div>
    <el-table
      :data="tableList"
      border
      style="margin: 10px 0"
      v-loading="loading"
      tooltip-effect="dark"
      @selection-change="$emit('selectionChange', $event)"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="name" label="名称" width="220" align="center">
      </el-table-column>
      <el-table-column prop="image" label="图片" width="140" align="center">
        <template slot-scope="scope">
          <el-image
            v-show="scope.row.image"
            :src="scope.row.image"
            fit="contain"
            style="width: 40px; height: 40px"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column prop="sort" label="排序" width="120" align="center">
      </el-table-column>
      <el-table-column label="状态" min-width="80" align="center">
        <template slot-scope="scope">
          <el-switch
            :active-value="1"
            :inactive-value="2"
            v-model="scope.row.status"
            @change="$emit('statusChange', scope.row)"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column
        prop="create_time"
        label="创建时间"
        width="160"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="操作"
        min-width="150"
        fixed="right"
        align="center"
      >
        <template slot-scope="scope">
          <el-button
            style="color: #67c23a"
            type="text"
            size="mini"
            @click="$emit('edit', scope.row)"
            >修改
          </el-button>
          <el-button
            style="color: red"
            type="text"
            size="mini"
            @click="$emit('del', scope.row)"
            >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :page="page"
      :page_size="page_size"
      :total="total"
      @currentChange="currentChange"
      @sizeChange="sizeChange"
    ></pagination>
  </div>
</template>

<script>
export default {
  name: "myTable",
  data() {
    return {}
  },
  props: {
    tableList: {
      type: Array,
      default: () => [],
    },
    page: {
      type: Number,
      default: 1,
    },
    page_size: {
      type: Number,
      default: 10,
    },
    total: {
      type: Number,
      default: 0,
    },
    loading: {
      type: Boolean,
      default: true,
    },
  },
  methods: {
    currentChange(e) {
      this.$emit("currentChange", e)
    },
    sizeChange(e) {
      this.$emit("sizeChange", e)
    },
  },
}
</script>

<style lang="scss" scoped>
.text {
  color: $base-status-color;
}
</style>
